import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { tool } from "@langchain/core/tools";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { z } from "zod";
import { ChatDeepSeek } from '@langchain/deepseek';

const transport = new StdioClientTransport({
  command: "node",
  args: ["server.js"]
});

const client = new Client(
  {
    name: "example-client",
    version: "1.0.0"
  },
  {
    capabilities: {
      prompts: {},
      resources: {},
      tools: {}
    }
  }
);

await client.connect(transport);

const search = tool(async ({ query }) => {
  if (query.toLowerCase().includes("sf") || query.toLowerCase().includes("san francisco")) {
    return "It's 60 degrees and foggy."
  }
  return "It's 90 degrees and sunny."
}, {
  name: "search",
  description: "Call to surf the web.",
  schema: z.object({
    query: z.string().describe("The query to use in your search."),
  }),
});


const llm = new ChatDeepSeek({
  apiKey: "sk-757e87b3cd6143ac9ff7a8845c24b10a",
  model: "deepseek-chat",
  temperature: 0,
  // other params...
});

const agent = createReactAgent({
  llm: llm,
  tools: [search],
});

const result = await agent.invoke(
  {
    messages: [{
      role: "user",
      content: "what is the weather in sf"
    }]
  }
);
console.log(result);












// const listTools = await client.listTools();
// console.log(listTools);

// List prompts
// const prompts = await client.listPrompts();

// // Get a prompt
// const prompt = await client.getPrompt("example-prompt", {
//   arg1: "value"
// });

// List resources
// const resources = await client.listResources();
// console.log(resources);
// // Read a resource
// const resource = await client.readResource("file:///example.txt");

// // Call a tool
// const result = await client.callTool({
//   name: "example-tool",
//   arguments: {
//     arg1: "value"
//   }
// });